﻿<template>
  <div class="payFess-container">
    <el-card shadow="hover" :body-style="{ paddingBottom: '0' }"> 
      <el-form :model="queryParams" ref="queryForm" labelWidth="90">
        <el-row>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
            <el-form-item label="关键字">
              <el-input v-model="queryParams.searchKey" clearable="" placeholder="请输入模糊查询关键字"/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="账单编号">
              <el-input v-model="queryParams.billNumber" clearable="" placeholder="请输入账单编号"/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="账单类目">
               <el-select v-model="queryParams.itemBil" placeholder="请选择账单类目" @change="handleQuery">
                <el-option  value="0">全部</el-option>
                <el-option v-for="item in enumItemBills"  :value="item.key" :label="item.value"/>
               </el-select>
            </el-form-item>
          </el-col>
          
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="缴费时间">
              <el-date-picker type="daterange" v-model="queryParams.paymentTimeRange"  value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" />
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="支付方式">
              <el-select v-model="queryParams.paymentmethod" placeholder="请选择支付方式" @change="handleQuery">
                <el-option  value="0">全部</el-option>
                <el-option v-for="item in enumPaymentMethods"  :value="item.key" :label="item.value"/>
               </el-select>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
            <el-form-item >
              <el-button-group style="display: flex; align-items: center;">
                
                
                <el-button type="primary"  icon="ele-Search" @click="handleQuery" >查询</el-button>&nbsp;
                      <el-button icon="ele-Refresh" @click="() => queryParams = {}"> 重置 </el-button>
                        <el-button icon="ele-ZoomIn" @click="changeAdvanceQueryUI" v-if="!showAdvanceQueryUI" style="margin-left:5px;"> 高级查询 </el-button>
                        <el-button icon="ele-ZoomOut" @click="changeAdvanceQueryUI" v-if="showAdvanceQueryUI" style="margin-left:5px;"> 隐藏 </el-button>
                <!-- <el-button type="primary" style="margin-left:5px;" icon="ele-Plus" @click="openAddPayFess" v-auth="'payFess:add'"> 新增 </el-button>&nbsp; -->&nbsp;
                <!-- <el-button type="primary" icon="ele-Promotion"  v-auth="'payFess:export'" @click="handleExport">导出</el-button> -->
                <el-button type="primary" icon="ele-Promotion"   @click="handleExport">导出</el-button>
              </el-button-group>
            </el-form-item>
            
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <el-card class="full-table" shadow="hover" style="margin-top: 5px">
      <el-table
				:data="tableData"
				style="width: 100%"
				v-loading="loading"
				tooltip-effect="light"
                				row-key="id"
                @sort-change="sortChange"
				border="">
        <el-table-column prop="serialNumber" label="流水号"  show-overflow-tooltip="" />
        <el-table-column prop="billNumber" label="账单编号"  show-overflow-tooltip="">
          <template v-slot="scope">
            {{ scope.row.billNumber ? scope.row.billNumber.replace(/(.{4})(\d{6})(.{4})/, '$1****$3') : '' }}
          </template>
        </el-table-column>
        <el-table-column prop="houseName" label="所属房屋"  show-overflow-tooltip="" />
        <el-table-column prop="itemBil" label="账单类目"  show-overflow-tooltip="">
          <template v-slot="scope">
            {{ scope.row.itemBil==1?"代缴电费":scope.row.itemBil==2?"代缴水费":scope.row.itemBil==3?"物业费":scope.row.itemBil==4?"卫生费":"车位费" }}
          </template>
        </el-table-column>
        <el-table-column prop="paidAmount" label="实收金额"  show-overflow-tooltip="">
          <template v-slot="scope">
            ￥{{ scope.row.paidAmount.toFixed(2) }}
          </template>
        </el-table-column>
        <el-table-column prop="paymentTime" label="缴费时间"  show-overflow-tooltip="">
          <template v-slot="scope">
            {{ scope.row.paymentTime.substr(0,19).replaceAll('-','') }}
          </template>
        </el-table-column>
        <el-table-column prop="paymentmethod" label="支付方式"  show-overflow-tooltip="">
          <template v-slot="scope">
            {{ scope.row.paymentmethod==1?"现金":scope.row.paymentmethod==2?"微信":scope.row.paymentmethod==3?"支付宝":"银行卡"}}
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
				v-model:currentPage="tableParams.page"
				v-model:page-size="tableParams.pageSize"
				:total="tableParams.total"
				:page-sizes="[10, 20, 50, 100, 200, 500]"
				size="small"
				background=""
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				layout="total, sizes, prev, pager, next, jumper"
	/>
      <printDialog
        ref="printDialogRef"
        :title="printPayFessTitle"
        @reloadTable="handleQuery" />
      <editDialog
        ref="editDialogRef"
        :title="editPayFessTitle"
        @reloadTable="handleQuery"
      />
    </el-card>
  </div>
</template>

<script lang="ts" setup="" name="payFess">
  import { ref } from "vue";
  import { ElMessageBox, ElMessage } from "element-plus";
  import { auth } from '/@/utils/authFunction';
  import { getAPI } from '/@/utils/axios-utils';

  import { formatDate } from '/@/utils/formatTime';

import { enumPayItemBills } from '/@/api/payfess/payFess';
import { enumPaymentmethod } from '/@/api/payfess/payFess';
import{excelExports} from '/@/api/payfess/payFess';

  import printDialog from '/@/views/system/print/component/hiprint/preview.vue'
  import editDialog from '/@/views/payfess/payFess/component/editDialog.vue'
  import { pagePayFess, deletePayFess } from '/@/api/payfess/payFess';
import axios from "axios";

  const showAdvanceQueryUI = ref(false);
  const printDialogRef = ref();
  const editDialogRef = ref();
  const loading = ref(false);
  const tableData = ref<any>([]);
  const queryParams = ref<any>({});
  const tableParams = ref({
    page: 1,
    pageSize: 10,
    field: 'createTime', // 默认的排序字段
    order: 'descending', // 排序方向
    descstr: 'descending', // 降序排序的关键字符
    total: 0 as any,
  });

  const printPayFessTitle = ref("");
  const editPayFessTitle = ref("");

  // 改变高级查询的控件显示状态
  const changeAdvanceQueryUI = () => {
    showAdvanceQueryUI.value = !showAdvanceQueryUI.value;
  }

  // 查询操作
  const handleQuery = async () => {
    loading.value = true;
    var res = await pagePayFess(Object.assign(queryParams.value, tableParams.value));
    tableData.value = res.data.result?.items ?? [];
    tableParams.value.total = res.data.result?.total;
    loading.value = false;
  };

  // 列排序
  const sortChange = async (column: any) => {
	tableParams.value.field = column.prop;
	tableParams.value.order = column.order;
	await handleQuery();
  };

  // 打开新增页面
  // const openAddPayFess = () => {
  //   editPayFessTitle.value = '添加缴费';
  //   editDialogRef.value.openDialog({});
  // };


  // 删除
  // const delPayFess = (row: any) => {
  //   ElMessageBox.confirm(`确定要删除吗?`, "提示", {
  //   confirmButtonText: "确定",
  //   cancelButtonText: "取消",
  //   type: "warning",
  // })
  // .then(async () => {
  //   await deletePayFess(row);
  //   handleQuery();
  //   ElMessage.success("删除成功");
  // })
  // .catch(() => {});
  // };

  // 改变页面容量
  const handleSizeChange = (val: number) => {
    tableParams.value.pageSize = val;
    handleQuery();
  };

  // 改变页码序号
  const handleCurrentChange = (val: number) => {
    tableParams.value.page = val;
    handleQuery();
  };
  //枚举账单类目下拉框
  const enumItemBills = ref<any>([]);
  const handEnums = async () => {
    var res = await enumPayItemBills(enumItemBills.value)
    enumItemBills.value = res.data.result;

  }
  //枚举支付方式下拉框
  const enumPaymentMethods = ref<any>([]);
  const handEnumsTwo = async () => {
    var res = await enumPaymentmethod(enumPaymentMethods.value)
    enumPaymentMethods.value = res.data.result;
  }
  //导出
  const handleExport = async () => {

    const res = await excelExports(); 

    //创建blod对象     数据源
    const blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
    //创建a标签 用于下载
    const link = document.createElement('a');
    //设置下载属性
    link.setAttribute('href', URL.createObjectURL(blob));
    //设置文件名
    link.setAttribute('download', '缴费列表.xlsx');
    //隐藏
    link.style.visibility = 'hidden';
    //添加到body中
    document.body.appendChild(link);
    //点击下载
    link.click();
    //移除a标签
    document.body.removeChild(link);
    //释放URL
    URL.revokeObjectURL(link.href);
  }


  handleQuery();
  handEnums();
  handEnumsTwo();
</script>
<style scoped>
:deep(.el-input),
:deep(.el-select),
:deep(.el-input-number) {
	width: 100%;
}
</style>

